package com.teziyou.commodity.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

@SuppressWarnings({"rawtypes", "unchecked"})
public class OnSaleTicket extends Model<OnSaleTicket> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5818249889434104280L;
	
	public static final OnSaleTicket dao = new OnSaleTicket();
	
	public Page<OnSaleTicket> getFullTicketByPage(String scenicId, String name, String launchTime, String startTime
			, String endTime, int pageNo, int pageSize) {
		String select = "select * ";
		String sql = " from on_sale_ticket a left join ticket_info b "
				+ "on a.ticket_info_id = b.ticket_info_id where 1=1 ";
		List params = new ArrayList();
		if(StringUtils.isNotBlank(scenicId)) {
			sql += "and b.scenic_id = ? ";
			params.add(scenicId);
		}
		if(StringUtils.isNotBlank(name)) {
			sql += "and b.name like ? ";
			params.add("%"+name+"%");
		}
		if(StringUtils.isNotBlank(launchTime)) {
			sql += "and date_format(a.launch_time, '%Y-%m-%d') = ? ";
			params.add(launchTime);
		}
		if(StringUtils.isNotBlank(startTime)) {
			sql += "and a.from_time > ? ";
			params.add(startTime);
		}
		if(StringUtils.isNotBlank(endTime)) {
			sql += "and a.end_time < ? ";
			params.add(endTime);
		}
		Page<OnSaleTicket> page = paginate(pageNo, pageSize, select, sql, params.toArray());
		return page;
	}

}
